// db.js
const mysql = require('mysql2/promise');

const pool = mysql.createPool({
  host: 'localhost',
  user: 'root3',
  password: '123456',
  database: 'mini_code',
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0,
    typeCast(field, next) {
    if (field.type === 'VAR_STRING' || field.type === 'STRING') {
      return field.string();
    }
    return next();
  }
});

pool.query('SELECT DATABASE()').then(([rows]) => {
  console.log('当前数据库：', rows[0]);
});
pool.query('SHOW TABLES FROM mini_code').then(([rows]) => {
  console.log('当前表：', rows);
});

module.exports = pool;
